<?php
namespace M\Action;
use Common\Model;
use Common\Model\articleModel;
class IndexAction extends BaseAction{
	public function _initialize() {
        parent::_initialize();
        $this->_ad = D('ad')->cache(true, 10 * 60);
        $this->_mod = D('items')->cache(true, 5 * 60);
		C('DATA_CACHE_TIME',C('yh_site_cachetime'));
    }
    
	
public function mytan(){
$this->display();
}

public function mytannoscript(){
$this->display();
}


public function  index(){
$admap1['status']=1;
$admap2['status']=6;
$map['_complex'] = array(
    $admap1,
    $admap2,
    '_logic' => 'or'
);
$map['add_time']=0;
$ad = $this->_ad->where($map)->order('id desc')->select();
$adlist=array();
foreach($ad as $k=>$v){
$adlist[$v['status']][$k]['url']=$v['url'];
$adlist[$v['status']][$k]['img']=$v['img'];
}
$this->assign('ad_list_1', $adlist[1]);
$this->assign('ad_list_6', $adlist[6]);

if(C('yh_openduoduo')){
$this->_pddmod = D('pdditems')->cache(true, 3 * 60);
$where=array(
'coupon_discount'=>array('gt',10),
'sold_quantity'=>array('gt',100)
);
$pdditems=$this->_pddmod->field('id,goods_id,goods_name,goods_thumbnail_url,sold_quantity,min_group_price,coupon_discount,min_normal_price')->where($where)->order('id desc')->limit(8)->select();
$this->assign('pdditems',$pdditems);
}

  $where=array(
    'pass'=>1,
    'isshow'=>1,
    'ems'=>2,
    'status'=>'underway'
    );
  $jingxuan=$this->_mod->where($where)->field('id,pic_url,title,coupon_price,price,quan,shop_type,volume,add_time')->order('ordid asc,id desc')->limit(5)->select();
  $this->assign('jingxuan',$jingxuan);	

  $sqlwhere['pass'] = '1';
  $sqlwhere['isshow'] = '1';	
  $sqlwhere['ems'] = '1';	
  $sqlwhere['status'] = 'underway';
  if(C('yh_index_shop_type')){
  $sqlwhere['shop_type']=C('yh_index_shop_type');
  }
  $sqlwhere['quan']=array(array(
  'egt',
  C('yh_index_mix_price')
  ),
array(
  'elt',
 C('yh_index_max_price')
  ));
 $sqlwhere['volume']=array(array(
  'egt',
  C('yh_index_mix_volume')
  ),
array(
  'elt',
 C('yh_index_max_volume')
  ));

$items_list = $this->_mod->where($sqlwhere)->field('id,pic_url,title,coupon_price,commission_rate,price,quan,shop_type,volume,add_time')->order(C('yh_index_sort'))->limit(trim(C('yh_index_page_size')))->select();	
if($items_list){
$today=date('Ymd');
$goodslist=array();
foreach($items_list as $k=>$v){
$goodslist[$k]['id']=$v['id'];
$goodslist[$k]['pic_url']=$v['pic_url'];
$goodslist[$k]['title']=$v['title'];
$goodslist[$k]['commission_rate']=$v['commission_rate'];
$goodslist[$k]['coupon_price']=$v['coupon_price'];
$goodslist[$k]['price']=$v['price'];
$goodslist[$k]['quan']=intval($v['quan']);
$goodslist[$k]['shop_type']=$v['shop_type'];
$goodslist[$k]['volume']=$v['volume'];	
if($today==date('Ymd',$v['add_time'])){
$goodslist[$k]['is_new']=1;	
}else{
$goodslist[$k]['is_new']=0;		
}
if(C('APP_SUB_DOMAIN_DEPLOY')){
$goodslist[$k]['linkurl']=U('/item/',array('id'=>$v['id']));
}else{
$goodslist[$k]['linkurl']=U('item/index',array('id'=>$v['id']));
}
	
}
}

$this->assign('list',$goodslist);
$modarticle=new articleModel();
$article_list =$modarticle->where('status=1')
->order('ordid asc,id desc')
->field('title,cate_id,add_time,id,pic,info')
->limit(4)
->select();
if($article_list ){
    $goodslist=array();
    foreach($article_list as $k=>$v){
        $goodslist[$k]['id']=$v['id'];
        $goodslist[$k]['pic']=$v['pic'];
        $goodslist[$k]['cateid']=$v['cate_id'];
        $goodslist[$k]['title']=$v['title'];
        $goodslist[$k]['add_time']=date('Y-m-d',$v['add_time']);
        $goodslist[$k]['infocontent']=cut_html_str($v['info'],80);	
        if(C('APP_SUB_DOMAIN_DEPLOY') && C('URL_MODEL') == 2){
            $goodslist[$k]['linkurl']='/article/view_'.$v['id'];
        }else{
            $goodslist[$k]['linkurl']=U('/article/read',array('id'=>$v['id']));
        }
        
    }
    $this->assign('articlelist',$goodslist);
}


$this->_config_seo(C('yh_seo_config.index'));

	$this->display();  	
}


public function cate() {
$ad = $this->_ad->where(array('status'=>'1'))->order('id desc')->select();
$this->assign('ad_list', $ad);
$cateinfo = $this->_cate_mod->where(array('status'=>1))->select();
$article_list =$this->_article->where('status=1')
            ->field('id,title')
            ->order('ordid asc,id desc')
            ->limit(6)
            ->select();
$this->assign('article_list', $article_list);
	$this->_config_seo(C('yh_seo_config.index'));

	$this->display('list/index');  	
}



}